﻿/**************************************************************************
创建时间:	2020/5/15 15:06:26    
作	  者:	张存
邮 	  箱:	zhangcunliang@126.com

Copyright (c) zhcun.cn

描	述：
记	录：
***************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZhCun.Utils;

namespace ZhCun.Win
{
    public partial class FrmInput : FrmBaseModal
    {
        public FrmInput(Func<string, ApiResult> SaveHandle, string defStr = null)
        {
            InitializeComponent();
            this.SaveHandle = SaveHandle;
            txtInput.Text = defStr;
        }

        Func<string, ApiResult> SaveHandle;

        private void FrmInput_Load(object sender, EventArgs e)
        { }
        
        private void btnOK_Click(object sender, EventArgs e)
        {
            var r = SaveHandle(txtInput.Text);
            if (!r)
            {
                ShowMessage(r.msg);
            }
            else
            {
                this.DialogResult = DialogResult.OK;
            }
        }

        private void txtInput_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnOK.Focus();
            }
        }
    }
}